﻿@page "/gatewayconfig/variable"
@using System.Linq.Expressions;
@using BlazorComponent;
@using Masa.Blazor.Presets;
@using Microsoft.AspNetCore.Authorization;
@using Microsoft.Extensions.DependencyInjection
@using System.Collections.Concurrent
@using ThingsGateway.Admin.Application;
@using ThingsGateway.Admin.Blazor
@using ThingsGateway.Core.Extension
@using ThingsGateway.Foundation
@using ThingsGateway.Gateway.Application

@namespace ThingsGateway.Gateway.Blazor
@attribute [Authorize]
@inject UserResoures UserResoures
@attribute [RolePermission]
@inherits BaseComponentBase

@code {
    private List<Device> _queryDevices = new();
    private List<Device> _queryBusinessDevices = new();
    private void DeviceQuerySelections(string v)
    {
        if (string.IsNullOrEmpty(v))
        {
            return;
        }
        _queryDevices = _devices.Where(e => e.Name.ToLowerInvariant().IndexOf(v.ToLowerInvariant()) > -1).OrderBy(a => a.Name.Length).Take(20).ToList();
    }
    private void BusinessDeviceQuerySelections(string v)
    {
        if (string.IsNullOrEmpty(v))
        {
            return;
        }
        _queryBusinessDevices = _businessDevices.Where(e => e.Name.ToLowerInvariant().IndexOf(v.ToLowerInvariant()) > -1).OrderBy(a => a.Name.Length).Take(20).ToList();
    }


}
<AppDataTable @ref="_datatable" TItem="Variable" SearchItem="VariablePageInput" AddItem="VariableAddInput" EditItem="VariableEditInput"
              SearchModel="@_search" IsShowSearchKey
               QueryCallAsync="QueryCallAsync" AddCallAsync="AddCallAsync"
               EditCallAsync="EditCallAsync" DeleteCallAsync="DeleteCallAsync"
               IsMenuOperTemplate=false AddWidth="1600" EditWidth="1600"
                IsShowDetailButton
                IsShowQueryButton
               IsShowAddButton=@UserResoures.IsHasButtonWithRole("GatewayVariableAdd")
               IsShowDeleteButton=@UserResoures.IsHasButtonWithRole("GatewayVariableDelete")
               IsShowEditButton=@UserResoures.IsHasButtonWithRole("GatewayVariableEdit")>

     <SearchTemplate>

         <MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " Outlined Clearable
                     @bind-Value="context.Name" Label=@AppService.I18n.T(context.Description(x => x.Name)) />
         <MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " Outlined Clearable
                     @bind-Value="context.RegisterAddress" Label=@AppService.I18n.T(context.Description(x => x.RegisterAddress)) />

         <MAutocomplete Dense Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " CacheItems HideNoData Outlined
                        ItemValue="r=>r.Id" ItemText="r=>r.Name" OnSearchInputUpdate="DeviceQuerySelections"
                        Items="_queryDevices" Flat Clearable
                        @bind-Value="context.DeviceId" Label=@AppService.I18n.T(context.Description(x => x.DeviceId)) />

         <MAutocomplete Dense Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " CacheItems HideNoData Outlined
                        ItemValue="r=>r.Id" ItemText="r=>r.Name" OnSearchInputUpdate="BusinessDeviceQuerySelections"
                        Items="_queryBusinessDevices" Flat Clearable
                        @bind-Value="context.BusinessDeviceId" Label=@AppService.I18n.T(context.Description(x => x.BusinessDeviceId)) />


     </SearchTemplate>

     <AddTemplate>
         @GetRenderFragment(context)

    </AddTemplate>

    <EditTemplate>
        @GetRenderFragment(context)
    </EditTemplate>


    <OtherToolbarTemplate>

        <MMenu OffsetY Context="menu">
             <ActivatorContent>
                 <MButton @attributes="@menu.Attrs" Color="primary"
                          Class="my-1  mx-2 ">
                     @AppService.I18n.T("导出")
                    <AppChevronDown></AppChevronDown>
                </MButton>
            </ActivatorContent>
            <ChildContent>
                <MList>
                    <MListItem OnClick="()=>DownExportAsync(true)">@AppService.I18n.T("导出全部")</MListItem>
                        <MListItem OnClick="()=>DownExportAsync(false)">@AppService.I18n.T("导出搜索项")</MListItem>
                    </MList>
                </ChildContent>
            </MMenu>

            <MButton Disabled=@(!UserResoures.IsHasButtonWithRole("GatewayVariableAdd")) Class="mx-2 my-1" OnClick=@(()=>CopyClickAsync(context)) Color="primary">@AppService.I18n.T("复制")</MButton>
            <MButton Disabled=@(!UserResoures.IsHasButtonWithRole("GatewayVariableImport")) Class=" mx-2 my-1" OnClick=@(ImportClickAsync) Color="primary">
                @AppService.I18n.T("导入")
        </MButton>
        <MButton Disabled=@(!UserResoures.IsHasButtonWithRole("GatewayVariableClear")) Class="mx-2 my-1" OnClick=@(()=>DeleteAllAsync()) Color="primary">@AppService.I18n.T("清空")</MButton>
        </OtherToolbarTemplate>

        <ItemColTemplate>
            @switch (context.Header.Value)
        {
            case nameof(context.Item.Enable):
                <EnableChip Value="context.Item.Enable">
                </EnableChip>
                break;
            case nameof(context.Item.DeviceId):
                @(_devices.FirstOrDefault(a => a.Id == context.Item.DeviceId)?.Name)
                break;

            default:
                @if (context.Header.CellClass?.Contains("text-truncate") == true)
                {
                    <span title=@context.Value>
                        @context.Value
                    </span>
                }
                else
                {
                    @context.Value
                }
                break;
        }

    </ItemColTemplate>
</AppDataTable>



@code {



    RenderFragment GetRenderFragment(VariableAddInput context)
    {
        if (!_otherMethods.ContainsKey(context.DeviceId))
        {
            DeviceChanged(context.DeviceId);
        }

        RenderFragment renderFragment =
    @<div style="min-height:800px;">
        <MTabs @bind-Value="tab" Class="" Style="">
            <MTab Value=1>    @AppService.I18n.T("变量属性")    </MTab>
            <MTab Value=2>    @AppService.I18n.T("报警属性")    </MTab>
            <MTab Value=3>    @AppService.I18n.T("业务属性")    </MTab>


        </MTabs>
        <MTabsItems Value="tab">
            <MTabItem Value="1">
                <MCard Flat Elevation="0" Class="ma-5">
                    <MContainer>
                        <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center">

                            <MCol Md=12 Cols=12>
                                <MSubheader Style="max-height:24px" Class="font-weight-black text-subtitle-1">
                                    @AppService.I18n.T("基础属性")
                                </MSubheader>
                            </MCol>

                            <MCol Md=3 Cols=12>
                                <MTextField Dense Style="max-width:300px" Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.Name Label="@(context.Description(x => x.Name))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Style="max-width:300px" Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.Description Label="@(context.Description(x => x.Description))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Style="max-width:300px" Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.Unit Label="@(context.Description(x => x.Unit))" />
                            </MCol>



                            <MCol Md=3 Cols=12>
                                <MSelect Items=@(typeof(ProtectTypeEnum).GetEnumList()) Style="max-width:300px;"
                                         @bind-Value=@context.ProtectType Label=@(context.Description(x => x.ProtectType))
                                         MenuProps="@(props => { props.Auto = true; props.OffsetY = true; })"
                                         ItemText=@(u =>u.Description)
                                         ItemValue=@(u =>(ProtectTypeEnum)u.Value)
                                         Dense HideDetails=@("auto")
                                         Outlined></MSelect>
                            </MCol>

                            <MCol Md=3 Cols=12>
                                <MRadioGroup @bind-Value=@context.Enable Label=@(context.Description(x => x.Enable))
                                             Style="max-width:300px"
                                             Row Dense HideDetails="@("auto")">
                                    <MRadio Label=@AppService.I18n.T("是") Value=true></MRadio>
                                    <MRadio Label=@AppService.I18n.T("否") Value=false></MRadio>
                                </MRadioGroup>
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MRadioGroup @bind-Value=@context.RpcWriteEnable Label=@(context.Description(x => x.RpcWriteEnable))
                                             Style="max-width:300px"
                                             Row Dense HideDetails="@("auto")">
                                    <MRadio Label=@AppService.I18n.T("是") Value=true></MRadio>
                                    <MRadio Label=@AppService.I18n.T("否") Value=false></MRadio>
                                </MRadioGroup>
                            </MCol>



                        </MRow>

                        <MRow Class="mt-5" Justify="JustifyTypes.Start" Align="AlignTypes.Center">
                            <MCol Md=12 Cols=12>
                                <MSubheader Style="max-height:24px" Class="font-weight-black text-subtitle-1">
                                    @AppService.I18n.T("采集配置")
                                </MSubheader>
                            </MCol>

                            <MCol Md=3 Cols=12>
                                <MAutocomplete Dense Style="max-width:300px;" HideDetails=@("auto") CacheItems HideNoData Outlined
                                               ItemValue="r=>r.Id" ItemText="r=>r.Name" OnSearchInputUpdate="DeviceQuerySelections"
                                               Items="_queryDevices" Flat Clearable OnClick=@(()=>DeviceChanged(context.DeviceId))
                                               @bind-Value=@context.DeviceId Label="@context.Description(x=>x.DeviceId)" />

                            </MCol>
                            <MCol Md=9 Cols=12>
                                <MTextField Dense
                                            Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.RegisterAddress Label="@(context.Description(x => x.RegisterAddress))" />
                            </MCol>

                            <MCol Md=3 Cols=12>
                                <MTextField Dense Style="max-width:300px"
                                            Type="number" NumberProps=@(prop => { prop.Step = 10; })
                                            Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.IntervalTime Label="@(context.Description(x => x.IntervalTime))" />
                            </MCol>

                            <MCol Md=9 Cols=12>

                                <MSelect @bind-Value="context.OtherMethod" Label=@(context.Description(x => x.OtherMethod))
                                         Items=@(_otherMethods.ContainsKey(context.DeviceId)?_otherMethods[context.DeviceId]:new()) Clearable Outlined Color="primary"
                                         MenuProps="@(props => { props.Auto = true; props.OffsetY = true; })"
                                         ItemText=@(u =>u.Description)
                                         ItemValue=@(u =>u.Description)
                                         HideDetails=@("auto") Height="30"
                                         Dense>
                                </MSelect>

                            </MCol>


                            <MCol Md=3 Cols=12>
                                <MSelect Items=@(typeof(DataTypeEnum).GetEnumList()) Style="max-width:300px;"
                                         @bind-Value=@context.DataType Label=@(context.Description(x => x.DataType))
                                         MenuProps="@(props => { props.Auto = true; props.OffsetY = true; })"
                                         ItemText=@(u =>u.Description)
                                         ItemValue=@(u =>(DataTypeEnum)u.Value)
                                         Dense HideDetails=@("auto")
                                         Outlined></MSelect>
                            </MCol>

                            <MCol Md=12 Cols=12>
                                <MTextField Dense Style="min-width:300px"
                                            Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.ReadExpressions Label="@(context.Description(x => x.ReadExpressions))" />
                            </MCol>
                            <MCol Md=12 Cols=12>
                                <MTextField Dense Style="min-width:300px"
                                            Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.WriteExpressions Label="@(context.Description(x => x.WriteExpressions))" />
                            </MCol>

                        </MRow>


                        <MRow Class="mt-5" Justify="JustifyTypes.Start" Align="AlignTypes.Center">
                            <MCol Md=12 Cols=12>
                                <MSubheader Style="max-height:24px" Class="font-weight-black text-subtitle-1">
                                    @AppService.I18n.T("备用字段")
                                </MSubheader>
                            </MCol>


                            <MCol Md=3 Cols=12>
                                <MTextField Dense Style="max-width:300px" Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.Remark1 Label="@(context.Description(x => x.Remark1))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Style="max-width:300px" Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.Remark2 Label="@(context.Description(x => x.Remark2))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Style="max-width:300px" Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.Remark3 Label="@(context.Description(x => x.Remark3))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Style="max-width:300px" Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.Remark4 Label="@(context.Description(x => x.Remark4))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Style="max-width:300px" Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.Remark5 Label="@(context.Description(x => x.Remark5))" />
                            </MCol>
                        </MRow>

                    </MContainer>
                </MCard>
            </MTabItem>

            <MTabItem Value="2">
                <MCard Flat Elevation="0" Class="ma-5">
                    <MContainer>
                        <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center">

                            <MCol Md=12 Cols=12>
                                <MSubheader Style="max-height:24px" Class="font-weight-black text-subtitle-1">
                                    @AppService.I18n.T("布尔量关报警")
                                </MSubheader>
                            </MCol>

                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.BoolCloseAlarmText Label="@(context.Description(x => x.BoolCloseAlarmText))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.BoolCloseRestrainExpressions Label="@(context.Description(x => x.BoolCloseRestrainExpressions))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MRadioGroup @bind-Value=@context.BoolCloseAlarmEnable Label=@(context.Description(x => x.BoolCloseAlarmEnable))
                                             Style="max-width:300px"
                                             Row Dense HideDetails="@("auto")">
                                    <MRadio Label=@AppService.I18n.T("是") Value=true></MRadio>
                                    <MRadio Label=@AppService.I18n.T("否") Value=false></MRadio>
                                </MRadioGroup>
                            </MCol>


                        </MRow>
                        <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center">

                            <MCol Md=12 Cols=12>
                                <MSubheader Style="max-height:24px" Class="font-weight-black text-subtitle-1">
                                    @AppService.I18n.T("布尔量开报警")
                                </MSubheader>
                            </MCol>

                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.BoolOpenAlarmText Label="@(context.Description(x => x.BoolOpenAlarmText))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.BoolOpenRestrainExpressions Label="@(context.Description(x => x.BoolOpenRestrainExpressions))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MRadioGroup @bind-Value=@context.BoolOpenAlarmEnable Label=@(context.Description(x => x.BoolOpenAlarmEnable))
                                             Style="max-width:300px"
                                             Row Dense HideDetails="@("auto")">
                                    <MRadio Label=@AppService.I18n.T("是") Value=true></MRadio>
                                    <MRadio Label=@AppService.I18n.T("否") Value=false></MRadio>
                                </MRadioGroup>
                            </MCol>



                        </MRow>

                        <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center">

                            <MCol Md=12 Cols=12>
                                <MSubheader Style="max-height:24px" Class="font-weight-black text-subtitle-1">
                                    @AppService.I18n.T("数值高高报警")
                                </MSubheader>
                            </MCol>

                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.HHAlarmText Label="@(context.Description(x => x.HHAlarmText))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.HHAlarmCode Label="@(context.Description(x => x.HHAlarmCode))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.HHRestrainExpressions Label="@(context.Description(x => x.HHRestrainExpressions))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MRadioGroup @bind-Value=@context.HHAlarmEnable Label=@(context.Description(x => x.HHAlarmEnable))
                                             Style="max-width:300px"
                                             Row Dense HideDetails="@("auto")">
                                    <MRadio Label=@AppService.I18n.T("是") Value=true></MRadio>
                                    <MRadio Label=@AppService.I18n.T("否") Value=false></MRadio>
                                </MRadioGroup>
                            </MCol>



                        </MRow>

                        <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center">

                            <MCol Md=12 Cols=12>
                                <MSubheader Style="max-height:24px" Class="font-weight-black text-subtitle-1">
                                    @AppService.I18n.T("数值高报警")
                                </MSubheader>
                            </MCol>

                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.HAlarmText Label="@(context.Description(x => x.HAlarmText))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.HAlarmCode Label="@(context.Description(x => x.HAlarmCode))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.HRestrainExpressions Label="@(context.Description(x => x.HRestrainExpressions))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MRadioGroup @bind-Value=@context.HAlarmEnable Label=@(context.Description(x => x.HAlarmEnable))
                                             Style="max-width:300px"
                                             Row Dense HideDetails="@("auto")">
                                    <MRadio Label=@AppService.I18n.T("是") Value=true></MRadio>
                                    <MRadio Label=@AppService.I18n.T("否") Value=false></MRadio>
                                </MRadioGroup>
                            </MCol>



                        </MRow>

                        <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center">

                            <MCol Md=12 Cols=12>
                                <MSubheader Style="max-height:24px" Class="font-weight-black text-subtitle-1">
                                    @AppService.I18n.T("数值低报警")
                                </MSubheader>
                            </MCol>

                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.LAlarmText Label="@(context.Description(x => x.LAlarmText))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.LAlarmCode Label="@(context.Description(x => x.LAlarmCode))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.LRestrainExpressions Label="@(context.Description(x => x.LRestrainExpressions))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MRadioGroup @bind-Value=@context.LAlarmEnable Label=@(context.Description(x => x.LAlarmEnable))
                                             Style="max-width:300px"
                                             Row Dense HideDetails="@("auto")">
                                    <MRadio Label=@AppService.I18n.T("是") Value=true></MRadio>
                                    <MRadio Label=@AppService.I18n.T("否") Value=false></MRadio>
                                </MRadioGroup>
                            </MCol>



                        </MRow>

                        <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center">

                            <MCol Md=12 Cols=12>
                                <MSubheader Style="max-height:24px" Class="font-weight-black text-subtitle-1">
                                    @AppService.I18n.T("数值低低报警")
                                </MSubheader>
                            </MCol>

                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.LLAlarmText Label="@(context.Description(x => x.LLAlarmText))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.LLAlarmCode Label="@(context.Description(x => x.LLAlarmCode))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.LLRestrainExpressions Label="@(context.Description(x => x.LLRestrainExpressions))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MRadioGroup @bind-Value=@context.LLAlarmEnable Label=@(context.Description(x => x.LLAlarmEnable))
                                             Style="max-width:300px"
                                             Row Dense HideDetails="@("auto")">
                                    <MRadio Label=@AppService.I18n.T("是") Value=true></MRadio>
                                    <MRadio Label=@AppService.I18n.T("否") Value=false></MRadio>
                                </MRadioGroup>
                            </MCol>



                        </MRow>

                        <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center">

                            <MCol Md=12 Cols=12>
                                <MSubheader Style="max-height:24px" Class="font-weight-black text-subtitle-1">
                                    @AppService.I18n.T("自定义报警")
                                </MSubheader>
                            </MCol>

                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.CustomAlarmText Label="@(context.Description(x => x.CustomAlarmText))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.CustomAlarmCode Label="@(context.Description(x => x.CustomAlarmCode))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MTextField Dense Outlined HideDetails="@("auto")" Color="primary" @bind-Value=@context.CustomRestrainExpressions Label="@(context.Description(x => x.CustomRestrainExpressions))" />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MRadioGroup @bind-Value=@context.CustomAlarmEnable Label=@(context.Description(x => x.CustomAlarmEnable))
                                             Style="max-width:300px"
                                             Row Dense HideDetails="@("auto")">
                                    <MRadio Label=@AppService.I18n.T("是") Value=true></MRadio>
                                    <MRadio Label=@AppService.I18n.T("否") Value=false></MRadio>
                                </MRadioGroup>
                            </MCol>



                        </MRow>
                    </MContainer>
                </MCard>
            </MTabItem>

            <MTabItem Value="3">
                <MCard Flat Elevation="0" Class="ma-5">

                    <MContainer>
                        <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center">

                            <MCol Md=3 Cols=12>
                                <MAutocomplete Dense Style="max-width:400px;" HideDetails=@("auto") Class="my-1 mx-2 " CacheItems HideNoData Outlined
                                               ItemValue="r=>r.Id" ItemText="r=>r.Name" OnSearchInputUpdate="BusinessDeviceQuerySelections"
                                               Items="_queryBusinessDevices" Flat Clearable Label=@AppService.I18n.T(typeof(Device).GetDescription(nameof(Device.Name)))
                                               @bind-Value=_choiceUploadDeviceId />
                            </MCol>
                            <MCol Md=3 Cols=12>
                                <MButton Class="mx-2 my-1" OnClick=@(()=>RefreshClickAsync(context)) Color="primary">@AppService.I18n.T("添加业务属性")</MButton>
                            </MCol>


                        </MRow>
                        @if (context.VariablePropertys != null)
                    {
                        @foreach (var item in context.VariablePropertys.ToList())
                    {
                    var data=_businessDevices.FirstOrDefault(a => a.Id == item.Key);

                        @if(data!=null)
                    {
                        <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center">
                            <MCard Rounded=true Elevation=1 Class="ma-2 pa-3" Width=@("100%")>
                                <MCardActions>
                                    <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center">

                                        @($"{data.Name}  ({data.PluginName})")

                                        <MSpacer></MSpacer>
                                        <MButton OnClick=@(() =>context.VariablePropertys.Remove(item.Key)) Color="primary">@AppService.I18n.T("删除") </MButton>
                                    </MRow>
                                </MCardActions>
                                <MRow>
                                    @foreach (var property in item.Value ?? new())
                                {
                                var isBigText=property.Name.Contains("BigText");
                                int md=isBigText?12:4;
                                var dict=PluginService.GetVariablePropertyTypes(data.PluginName);
                                if(!dict.ContainsKey(property.Description))
                                {
                                continue;
                                }
                                    <MCol Md=md Cols=12 Class="pa-3">
                                        <DynamicPropertyComponent IsBigText=isBigText Type="dict[property.Description].PropertyType" @bind-Value=property.Value
                                                                  Description=@(property.Description) Remark=@(dict[property.Description].Remark)>
                                        </DynamicPropertyComponent>
                                    </MCol>

                                }

                                </MRow>

                            </MCard>
                        </MRow>
                    }
                    else{
                    context.VariablePropertys.Remove(item.Key);
                    }
                    }
                    }
                    </MContainer>
                </MCard>
            </MTabItem>

        </MTabsItems>
    </div>
    ;
        return renderFragment;
    }
    private StringNumber tab;
}

